<script setup lang="ts">


import { getCurrentInstance, onMounted, reactive, ref } from "vue";
import { FormInstance } from "element-plus";
import DictTag from "@/components/DictTags/index.vue";
import { reqScorePageList } from "@/api/credit/peasants/score";
import ScoreDialog from "./components/scoreDialog.vue";
import FinishDialog from "./components/finishDialog.vue";


const ruleFormRef = ref();
// 查询条件
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  hzName: undefined,
  idCardNumber: undefined
});
const total = ref(0);
const loading = ref(true);
const tableData = ref([]);
const scoreDialogRef = ref();
const finishDialogRef = ref();
const { proxy }: any = getCurrentInstance();
// 查询
const getPageList = () => {
  queryParams.pageNum = 1;
  getList();
};

const getList = async () => {
  loading.value = true;
  await reqScorePageList(queryParams).then((req: any) => {
    if(req.code === 200){
      tableData.value = req.rows
      total.value = req.total
    }else {
      proxy.$modal.msgError(req.message);
    }
  }).catch(() => {})
  loading.value = false;
};

// 重置按钮
const reset = (formEl: FormInstance | undefined) => {
  // 将数据置空
  formEl.resetFields();
  Object.keys(queryParams).forEach((key) => {
    if (key === "pageNum") queryParams[key] = 1;
    else if (key === "pageSize") queryParams[key] = 10;
    else queryParams[key] = undefined;
  });
  // 再次进行查询
  getPageList();
};


// 进行评分
const startScoring = (row) => {
  scoreDialogRef.value.show(row)
};

const handleShowScore = (row: {}) => {
  //数据评分情况查询
  finishDialogRef.value.show(row)
}

onMounted(() => {
  getPageList();
});

</script>

<template>
  <div class="app-container">
    <div class="header">
      <el-form :inline="true" :model="queryParams" ref="ruleFormRef">
        <el-form-item label="户主姓名" prop="hzName">
          <el-input v-model="queryParams.hzName" placeholder="请输入户主姓名" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="idCardNumber">
          <el-input v-model="queryParams.idCardNumber" :maxlength="18"  show-word-limit placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getPageList" icon="Search">查询</el-button>
          <el-button icon="Refresh" @click="reset(ruleFormRef)">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="footer">
      <div class="table-inner">
        <el-table v-loading="loading" :data="tableData" style="width: 100%" border>
          <el-table-column label="ID" prop="scoreId" width="100" align="center"></el-table-column>
          <el-table-column label="姓名" prop="hzBaseDto.hzName" width="100" align="center">
          </el-table-column>
          <el-table-column label="手机号码" prop="hzBaseDto.hzPhoneNumber" width="120" align="center"></el-table-column>
          <el-table-column label="身份证号码" prop="hzBaseDto.hzIdCardNumber" width="180" align="center"></el-table-column>
          <el-table-column label="评分人员姓名" prop="nickName" width="180" align="center"></el-table-column>
          <el-table-column label="评分人员手机" prop="userPhonenumber" width="180" align="center"></el-table-column>
          <el-table-column
            label="家庭住址"
            prop="hzBaseDto.familyAddress"
            align="center"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column label="全部评分情况" prop="hzBaseDto.ratingStatus" width="130" align="center">
            <template #default="scope">
              <DictTag
                :value="scope.row.hzBaseDto.ratingStatus"
                :options="dict.type.pea_rating_status"
                @click="handleShowScore(scope.row)"
              ></DictTag>
            </template>
          </el-table-column>
          <el-table-column label="评分情况" prop="finishStatus" width="85" align="center">
            <template #default="scope" >
              <DictTag
                :value="scope.row.finishStatus"
                :options="dict.type.cre_score_status"
              ></DictTag>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" prop="createTime" width="170" align="center"></el-table-column>
          <el-table-column label="操作" width="270" align="center">
            <template #default="scope">
              <el-button
                type="success"
                size="small"
                icon="Edit"
                @click="startScoring(scope.row)"
                v-if="scope.row.isScore && scope.row.finishStatus == 0"
              >
                评分
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination">
        <!--分页器            -->
        <el-pagination
          v-show="total > 0"
          v-model:current-page="queryParams.pageNum"
          v-model:page-size="queryParams.pageSize"
          :page-sizes="[5, 10, 15, 20, 25, 30]"
          :background="true"
          layout="prev, pager, next, jumper, ->,  sizes, total"
          :total="total"
          @current-change="getList"
          @size-change="getList"
        />
      </div>
    </div>


    <scoreDialog ref="scoreDialogRef" @getList="getList"></scoreDialog>
    <finishDialog ref="finishDialogRef"></finishDialog>
  </div>


</template>

<script lang="ts">
export default {
  dicts: ["pea_sex", "cre_score_status", "pea_rating_status"]
};
</script>

<style scoped lang="scss">

@import "./index";

</style>
